*   Author:    	Annekatrin Deglow, Ralph Sundberg
*	Contact:   	annekatrin.deglow@pcr.uu.se, ralph.sundberg@pcr.uu.se
*	Do-file:   	ADRS_online_appendix.do
*   Dataset:   	ADRS_analysis.dta, ADRS_online_appendix_missing.dta, ADRS_online_appendix_placebo2010.dta, ADRS_online_appendix_placebo2011.dta
*	Article:   	To Blame or To Support? Large-scale Insurgent Attacks on Civilians and Public Trust in State Institutions
*	Journal:	International Studies Quarterly

* 	ONLINE APPENDIX

*-------------------------------------------------------------------------------
*	Program Setup 
*-------------------------------------------------------------------------------
clear
//set your working directory
version 15 
use "ADRS_analysis", clear
set more off
set scheme plotplain


*-------------------------------------------------------------------------------	
* Descriptive Statistics
*-------------------------------------------------------------------------------	

* Table A.2
sum x34r x34l x34b treatment_dummy gender_dummy age income education radio_dummy pashtun_dummy


*-------------------------------------------------------------------------------	
* Coefficients for Categorical Outcome Variables
*-------------------------------------------------------------------------------	

* Table A.3 
foreach y in x34r x34l x34b { 
									 		
	// Models with pre-treatment covariates (M2, M4, M6) 
	ologit  `y' treatment_dummy gender_dummy age radio_dummy pashtun_dummy i.income i.education 
}

*-------------------------------------------------------------------------------	
* Partial Proportional Odds Models
*-------------------------------------------------------------------------------	

* Table A.4
// Uses gologit command: Williams, Richard. 2006. "Generalized Ordered Logit/ Partial Proportional Odds Models for Ordinal Dependent Variables." The Stata Journal 6(1):58-82

// Parliament (treatment violates the assumption)
gologit2 x34l treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy, pl(gender_dummy age i.income i.education radio_dummy pashtun_dummy)

// Police (gender violates the assumption)
gologit2 x34b treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy, pl(treatment_dummy age i.income i.education radio_dummy pashtun_dummy) 


*-------------------------------------------------------------------------------	
* Additive Index for Institutional Trust 
*-------------------------------------------------------------------------------	
reg 	add_index treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy


*-------------------------------------------------------------------------------	
* P-values Corrected for Multiple Hypotheses Testing
*-------------------------------------------------------------------------------
// Corrected p-values are computed in R; see separate script "ADRS_analysis.R"


*-------------------------------------------------------------------------------	
* Violations of Assumptions
*-------------------------------------------------------------------------------

* Table A.7: Additional Balance Tests
// mu_1 = mean control group
// mu_2 = mean treatment group
// b    = difference mean control and mean treatment
// p    = p-value (difference mean control and mean treatment)

estpost ttest age gender_dummy pashtun_dummy radio_dummy, by(treatment_dummy)

// P-values for chi-squared tests 
tab 	income treatment_dummy, chi2
tab 	education treatment_dummy, chi2 

*-------------------------------------------------------------------------------
* Table A.8: Main models with matched data

* Identify variables affecting IDVs, see p.10 online appendix
// education, gender, age, pashtun consistently imbalanced across IDVs
ologit x34r  gender_dummy age i.income i.education pashtun_dummy radio_dummy
ologit x34l  gender_dummy age i.income i.education pashtun_dummy radio_dummy
ologit x34b  gender_dummy age i.income i.education pashtun_dummy radio_dummy

* Identify variables affecting DV, see p.10 online appendix
// gender, age, pashtun consistenty imbalanced for DV
logit treatment_dummy gender_dummy age i.income i.education pashtun_dummy radio_dummy


* gender, age and pashtun are the consistent imbalancers across IDV and DV if p-value cut-off at .10. Otherwise .05. See p.10 online appendix.

* 'Generous' matching model for imbalances. See p.10 online appendix
imb gender_dummy age pashtun_dummy, treatment(treatment_dummy)
cem gender_dummy age pashtun_dummy, treatment(treatment_dummy)

* Models for 'generous' matching. See p.10 online appendix

*M1 Table A.8
ologit x34r treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]

*M3 Table A.8
ologit x34l treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]

*M5 Table A.8
ologit x34b treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]

*M7 Table A.8
reg add_index treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]


* 'Less generous' matching model for imbalances. See p.10 online appendix

imb gender_dummy, treatment (treatment_dummy)
cem gender_dummy, treatment (treatment_dummy)

* Models for 'less generous' matching. See p.10 online appendix

*M2 Table A.8
ologit x34r treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]

*M4 Table A.8
ologit x34l treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]

*M6 Table A.8
ologit x34b treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]

*M8 Table A.8
reg add_index treatment_dummy gender_dummy age pashtun_dummy radio_dummy i.income i.education [iweight=cem_weights]


*-------------------------------------------------------------------------------
* Table A.10: Estimates Using Different Bandwidths
// Note: -1 day is day of attack

foreach y in x34r x34l x34b { 

	// Compare +/- 1 day 
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy if day_int==21 | day_int==22 
	
	// Compare +/- 2 day 
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy if day_int==20 | day_int==21 | day_int==22 | day_int==23

	// Compare +/- 3 day 
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy if day_int==18 | day_int==20 | day_int==21 | day_int==22 | day_int==23 | day_int==24

	// Compare +/- 4 day 
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy if day_int==17 | day_int==18 | day_int==20 | day_int==21 | day_int==22 | day_int==23 | day_int==24 | day_int==25 

	// Compare - 4 day/+5 days, i.e. adding sequentually the remaining days in the treatment group 
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy if day_int==17 | day_int==18 | day_int==20 | day_int==21 | day_int==22 | day_int==23 | day_int==24 | day_int==25 | day_int==26
	
	// Compare - 4 day/+6 days, i.e. adding sequentually the remaining days in the treatment group 
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy if day_int==17 | day_int==18 | day_int==20 | day_int==21 | day_int==22 | day_int==23 | day_int==24 | day_int==25 | day_int==26 | day_int==27
	
	// Compare - 4 day/+7 days, i.e. adding sequentually the remaining days in the treatment group (these are the full models from Table 1)
	ologit `y' treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy		
}


*-------------------------------------------------------------------------------
* Table A.11: Assessing Pre-existing Time Trends

foreach y in x34r x34l x34b { 

	ologit `y' i.treatment_dummy##c.time  gender_dummy age i.income i.education radio_dummy pashtun_dummy
	
	// Change in predicted probabilities
	margins, dydx(time) at(treatment_dummy=(0 1)income=4 education=1 gender_dummy=1 radio_dummy=0 pashtun_dummy=0  age =35.78303) predict(outcome(4))

	// Figure 1: Effect of Time on Highest Level of Institutional Trust by Treatment status (note: titles changed manually for each outcome)
	marginsplot, yline(0, lcolor(red)) recast(scatter) ///
	plotopts(mcolor(black) msymbol(o)) level(95) title("") ///
	xtitle("")   ///
	ytitle("Change in predicted probability") ///
	yscale(range(-.05(0.01).05)) ylabel(-.05(0.01)0.05) ///
	xlabel(0 "Control" 1 "Treatment" ,labsize(vsmall) ang(0)) 
}


*-------------------------------------------------------------------------------
* Table A.14: Placebo Test in Control Group

gen 	treatment_placebo =.
replace	treatment_placebo=0 if day_int==17 | day_int==18 | day_int==19 |  day_int==20
replace	treatment_placebo=1 if day_int==21 
tab 	treatment_placebo


foreach y in x34r x34l x34b { 

	ologit `y' treatment_placebo gender_dummy age i.income i.education radio_dummy pashtun_dummy
}


*-------------------------------------------------------------------------------
* Table A.15: Compliance - subsample analysis excluding 22 June

foreach y in x34r x34l x34b { 

	ologit `y' i.treatment_dummy gender_dummy age radio_dummy pashtun_dummy i.income i.education if day_int!=22
	
	// Changed in predicted probabilities
	margins, dydx(treatment_dummy) at(income=4 education=1 gender_dummy=1 radio_dummy=0 pashtun_dummy=0  age =35.78303) predict(outcome(1)) predict(outcome(2)) predict(outcome(3)) predict(outcome(4))
	
	// Figure 2: The change in predicted probability for each outcome category of trust in state institutions dueto exposure to the attack (note: titles changed manually for each outcome)
	marginsplot, yline(0, lcolor(red)) plotopts(mcolor(black) msymbol(o)) level(95) title("")  recast(scatter) ///
	xtitle("",size(small)) ///
	ytitle("Change in predicted probability",size(small))  ///
	xlabel(1 "None" 2 "Not very much" 3 "A fair amount" 4 "A great deal" ,labsize(vsmall)) ///
	yscale(range(-0.15(0.05)0.15)) ylabel(-0.15(0.05)0.15)
	
}


*-------------------------------------------------------------------------------
* NOTE: Producing the results in Table A.9, A.12 and A.13 require loading new datasets 

* Table A.9: Analysis of Non-responses
clear
//set your working directory
use "ADRS_online_appendix_missing", clear
version 15 

ttest missing_x34r, by(treatment_dummy)  // Local government
ttest missing_x34l, by(treatment_dummy)  // Parliament
ttest missing_x34b,  by(treatment_dummy) // Police


*-------------------------------------------------------------------------------
* Table A.12: Annual Time Trends (Placebo test for 2011)
clear
//set your working directory
use "ADRS_online_appendix_placebo2011.dta", clear
version 15 

ologit 		x34r treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy 
ologit 		x34l treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy 
ologit 		x34b treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy 



* Table A.13: Annual Time Trends (Placebo test for 2010)
clear
//set your working directory
use "ADRS_online_appendix_placebo2010.dta", clear
version 15 

ologit 		x34l treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy 
ologit 		x34b treatment_dummy gender_dummy age i.income i.education radio_dummy pashtun_dummy 





